<?php


namespace app\admin\controller;
use app\admin\model\User as UserModel;

// 用户模块
class User extends Base
{

    /**
     * 用户列表
     * date 2020/8/15 14:09
     */
    public function user_list() {
        if(IS_POST) {
            $where = [];
            if(!empty($_GET['nickname'])) $where[] = ['nickname', 'like', "%{$_GET['nickname']}%"];
            if(!empty($_GET['mobile'])) $where[] = ['mobile', '=', $_GET['mobile']];
            $db   = UserModel::where($where)->order('id desc');
            $list = $db->page(paginator())->select();
            if(count($list)){
                foreach ($list as $key => $value) {
                    $value['avatar'] = table_img($value['avatar']);
                }
            }
            admin_response(0, 'success', $list, $db->count());
        }
        return $this->render_table([
            "page"=>true,
            "cols" => [
                ["type"=>"checkbox"],
                ["field"=>"id", "title"=>"编号","align"=>"center"],
                ["field"=>"avatar", "title"=>"头像","align"=>"center"],
                ["field"=>"nickname", "title"=>"昵称","align"=>"center"],
                ["field"=>"openid", "title"=>"openid","align"=>"center"],
                ["field"=>"mobile", "title"=>'手机号',"align"=>"center"]

            ],
            "where"=>[
                'title'  => ['type'=>'input', 'title'=>'关键字','placeholder'=>'题目名称搜索'],
            ]

        ],false);
    }
}